package config;

import com.lmax.disruptor.dsl.Disruptor;
import factory.DisruptorFactory;
import factory.EventThreadFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadFactory;

@Configuration
@ConditionalOnClass(Disruptor.class)
@ConditionalOnProperty()
@EnableConfigurationProperties(DisruptorProperties.class)
public class DisruptorAutoConfiguration {

    @Autowired
    private DisruptorProperties disruptorProperties;

    @Bean
    public EventThreadFactory eventThreadFactory(){
        return new EventThreadFactory(disruptorProperties);
    }

}
